package com.huifaapp.mall.activity;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.blankj.utilcode.util.SPUtils;
import com.huifaapp.mall.R;
import com.huifaapp.mall.afinal.SPConstants;

import java.util.Timer;
import java.util.TimerTask;

public class WelcomeActivityone extends AppCompatActivity {
    private LinearLayout ll_activityone;
    boolean isClick;
    private TextView tv_introduc;
    private int recLen = 9;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_welcome_activityone);
        ll_activityone = (LinearLayout) findViewById(R.id.activity_onell);
        tv_introduc= (TextView) findViewById(R.id.tv_introduc);
        tv_introduc.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                recLen=-1;
//                SPUtils.getInstance().put(SPConstants.KEY_YINDAO,true);
//                startActivity(new Intent(IntroductionPageActivity.this, LoginActivity.class));
//
//                finish();

            }
        });
        Message message = handler.obtainMessage(1);     // Message
        handler.sendMessageDelayed(message, 1000);
//        final Intent it = new Intent(this, MainFragment.class); //你要转向的Activity
//        final Timer timer = new Timer();
//        TimerTask task = new TimerTask() {
//            @Override
//            public void run() {
//                startActivity(it); //执行
//            }
//        };
//        timer.schedule(task, 1000 * 3); //10秒后
final String url=getIntent().getStringExtra("url");
        ll_activityone.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(WelcomeActivityone.this, com.huifaapp.mall.activity.Homefragment.WebActivity.class);
                intent.putExtra("url",url);
                startActivity(intent);
                recLen=0;
//                timer.cancel();
                isClick = true;

            }
        });
    }

    final Handler handler = new Handler(){

        public void handleMessage(Message msg){
            // handle message
            switch (msg.what) {
                case 1:
                    recLen--;
                    tv_introduc.setText("跳过" + recLen+"s");

                    if(recLen > 0){
                        Message message = handler.obtainMessage(1);
                        handler.sendMessageDelayed(message, 1000);      // send message
                    }else{
                        tv_introduc.setVisibility(View.GONE);
                        SPUtils.getInstance().put(SPConstants.KEY_YINDAO,true);
                        startActivity(new Intent(WelcomeActivityone.this, MainFragment.class));
                        finish();
                    }
            }

            super.handleMessage(msg);
        }
    };
    @Override
    protected void onResume() {
        super.onResume();
        if (isClick){
            Intent it = new Intent(this, MainFragment.class); //你要转向的Activity
            startActivity(it);
            finish();
        }
    }
}

